#include "smallwidget.h"
#include "ui_smallwidget.h"

SmallWidget::SmallWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SmallWidget)
{
    ui->setupUi(this);


    //修改SpinBox 右侧滚动条跟着移动
    void(QSpinBox::*spinBoxPointer)(int) = &QSpinBox::valueChanged;

    connect(ui->spinBox, spinBoxPointer, this, [=](int val){
        ui->horizontalSlider->setValue(val);
    });

    //右侧滚动条移动，左侧跟着改变数字
    connect(ui->horizontalSlider, &QSlider::valueChanged, this, [=](int val){
        ui->spinBox->setValue(val);
    });
}

SmallWidget::~SmallWidget()
{
    delete ui;
}

//设置值
void SmallWidget::setValue(int val){
    ui->horizontalSlider->setValue(val);
}

//获取值
int SmallWidget::getValue(){
    return ui->horizontalSlider->value();
}
